package com.ws.entity;

import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 王硕
 * @version jdk21
 * @className Bike
 * @description
 * @date 2024/11/16 14:14
 */
@Data
@Accessors(chain = true)
public abstract class BaseBike implements Cloneable{
    // 单车编号
    private Integer bid;
    // 单车名称
    private String bname;
    // 单车状态
    private Integer status;
    // 单车借出时间
    private LocalDateTime borrowTime;
    // 单车归还时间
    private LocalDateTime returnTime;

    @Override
    public BaseBike clone(){
        try {
            BaseBike clone=(BaseBike)super.clone();
            int newId = this.getBid()+1;
            clone.setBid(newId);
            String name = this.getBname().split("_")[0];
            clone.setBname(name);
            clone.setStatus(1);
            return clone;
        }catch (CloneNotSupportedException e){
            throw new AssertionError();
        }
    }
    public String getFormattedBorrowTime() {
        if (borrowTime != null) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            return borrowTime.format(formatter);
        }
        return "未借出";
    }
    public String getFormattedReturnTime() {
        if (returnTime != null) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            return returnTime.format(formatter);
        }
        return "未归还";
    }
}
